/**
 * 
 */
package com.xbang.attendance.web.action.warehouse.stockoutlog;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.attendance.entity.order.StockOutLog;
import com.xbang.attendance.service.InventoryService;
import com.xbang.attendance.service.SystemService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 */
public class Index extends SearchActionSupport {

	private static final long serialVersionUID = 2886204759816132683L;

	

	private List<StockOutLog> stockOutLogs = new ArrayList<StockOutLog>();

	private StockOutLog stockOutLog;
	
	
	@Autowired
	private SystemService systemService;

	@Autowired
	private InventoryService inventoryService;
	private Date beginDate;
	private Date endDate;
	
//	/*
//	 * (non-Javadoc)
//	 * 
//	 * @see com.opensymphony.xwork2.ActionSupport#execute()
//	 */
//	@Override
//	public String execute() throws Exception {
//
//		return super.execute();
//	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	@Action("/warehouse/stockoutlog/list")
	public String execute() throws Exception {
		String hqlSentence = "FROM StockOutLog log WHERE 1=1";
		
		//inventoryRecords = systemService.searchForList(hqlSentence, new HashMap());
		
		if (page != null) {
			if (currPageId.intValue() != -1 && currPageId.intValue() > 0) {
				page.setCurrentPage(currPageId);
			}
		}
		
		Result result = systemService.searchByPage(hqlSentence, searchComponent, page);

		stockOutLogs = result.getItems();
			
		
		page = result.getPage();

		return "index";
	}
	@Action("/stock/stockoutlog/export")
	public String export() throws Exception{
		try{
			String exportFile = "";
			String webPath = ServletActionContext.getRequest().getRealPath("//download//warehouse//product");
			HttpServletRequest request = ServletActionContext.getRequest();
			String urlPath = request.getRequestURL().toString();
			String contextPath = request.getContextPath();
			String contextURL = urlPath.split(contextPath)[0] + contextPath;
			exportFile = contextURL + "/download/warehouse/product/" + inventoryService.genericExcelFile(webPath, beginDate, endDate);
			//System.out.println(exportFile);
			
			return "r:" + exportFile;
		}catch (Exception e) {
			e.printStackTrace();
			logger.info(e);
			return ERROR;
		}
	}
	@Action("/warehouse/stockoutlog/toexport")
	public String toexprot() throws Exception {

		return "dowload";
	}
	


	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}
	

	public Date getBeginDate() {
		return beginDate;
	}
	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public SystemService getSystemService() {
		return systemService;
	}

	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	public InventoryService getInventoryService() {
		return inventoryService;
	}

	public void setInventoryService(InventoryService inventoryService) {
		this.inventoryService = inventoryService;
	}
	public List<StockOutLog> getStockOutLogs() {
		return stockOutLogs;
	}
	public void setStockOutLogs(List<StockOutLog> stockOutLogs) {
		this.stockOutLogs = stockOutLogs;
	}
	public StockOutLog getStockOutLog() {
		return stockOutLog;
	}
	public void setStockOutLog(StockOutLog stockOutLog) {
		this.stockOutLog = stockOutLog;
	}

}
